package dotdashdot.bradz.trendsettr;

import java.sql.Timestamp;
import java.util.ArrayList;

import android.graphics.Point;
import android.util.Log;
import android.view.View;

public class ClassGraphInfo {
	ArrayList<ClassGraphData> values;
	String trend, meta;
	View v;
	private ClassUberLogger logger;
				//client point , server point
	ClassGraphInfo(ArrayList<ClassGraphData> values, String meta, String trend, View v){
		this.values = new ArrayList<ClassGraphData>(values);
		this.trend = trend;
		this.meta = meta;
		this.v = v;
		logger = new ClassUberLogger("ClassGraphInfo");
		logger.info("Class Initialized");
	}
	ClassGraphInfo(ClassGraphInfo info){
		this.values = new ArrayList<ClassGraphData>(info.values);
		this.meta = info.meta;
		this.trend = info.trend;
		this.v = info.v;
		logger = new ClassUberLogger("ClassGraphInfo");
		logger.info("Class Initialized");
	}
	public void add_graph_point(ClassGraphData data){
		values.add(data);
	}
	public Timestamp get_min_date(){
		Timestamp min_date = new Timestamp((new java.util.Date()).getTime());
		for(ClassGraphData value:values){
			if(value.date.before(min_date)){
				min_date = value.date;
			}
		}
		logger.info("Found min date: " + min_date.toString());
		return min_date;
	}
	public Timestamp get_max_date(){
		Timestamp max_date = new Timestamp(0);
		for(ClassGraphData value:values){
			if(value.date.after(max_date)){
				max_date = value.date;
			}
		}
		logger.info("Found max date: " + max_date.toString());
		return max_date;
	}
	public Number[] get_vote_array(){
		float count_ups = 0;
		float count_total = 0;
		ArrayList<Number> return_values = new ArrayList<Number>();
		//return_values.add((Number) 0);
		logger.info("Reading vote values...");
		for(ClassGraphData value:values){
			
			logger.info("Votes: " + value.votes);
			logger.info("Downvotes: " + value.downvotes);
			logger.info("Date: " + value.date);
			
			count_ups += Math.abs(value.votes);
			count_total += Math.abs(value.downvotes) + Math.abs(value.votes);
			return_values.add((Number) ((count_ups/count_total) * 100));
			
		}
		logger.info("Done reading vote values...");
		Number[] return_array = new Number[return_values.size()];
		return_array = return_values.toArray(return_array);
		return return_array;
	}
	public Number[] get_date_array(){
		ArrayList<Number> return_values = new ArrayList<Number>();
		for(ClassGraphData value:values){
			return_values.add(value.date.getTime());
		}
		Number[] return_array = new Number[return_values.size()];
		return_array = return_values.toArray(return_array);
		logger.info("Returning Date Array");
		return return_array;
	}
	public boolean dates_same(){
		if(values.size()>0){
			ClassGraphData first_date = values.get(0);
			for(ClassGraphData value:values){
				if(first_date.date != value.date){
					return false;
				}
			}
			return true;
		}
		return false;
	}
}
